﻿using CTM.Web.Models.Input;
using CTM.Web.Utils;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;

namespace CTM.Web.Models.View.Note
{
    public class NoteViewModel
    {
        #region Properties

        public Guid Id { get; set; }

        [Required(ErrorMessage = "*")]
        [DataType(DataType.MultilineText)]
        public string Description { get; set; }

        public bool IsDeleted { get; set; }

        public DateTime CreatedOn { get; set; }

        [StringLength(128)]
        public string CreatedBy { get; set; }

        public DateTime? ModifiedOn { get; set; }

        [StringLength(128)]
        public string ModifiedBy { get; set; }

        #endregion

        #region Relationship

        public virtual Category Category { get; set; }
        public virtual ICollection<Input.Comment> Comments { get; set; }
        public virtual ICollection<Tag> Tags { get; set; }
        public virtual ApplicationUser Manager { get; set; }
        public virtual ApplicationUser Employee { get; set; }

        #endregion

        public NoteViewModel()
        {
            IsDeleted = false;
            CreatedOn = DateTime.UtcNow;
            Comments = new HashSet<Input.Comment>();
            Tags = new HashSet<Tag>();
        }

        public NoteViewModel(Input.Post note)
        {
            this.Id = note.Id;
            this.Description = note.Description;
            this.IsDeleted = note.IsDeleted;
            this.CreatedOn = ApplicationHelpers.ConvertToLocalTime(note.CreatedOn);
            this.CreatedBy = note.CreatedBy;
            this.ModifiedOn = note.ModifiedOn.HasValue ? ApplicationHelpers.ConvertToLocalTime(note.ModifiedOn.Value) : note.ModifiedOn;
            this.ModifiedBy = note.ModifiedBy;
            this.Category = note.Category;
            this.Comments = note.Comments;
            this.Tags = note.Tags;
            this.Manager = note.Manager;
            this.Employee = note.Employee;
        }
    }

    public class NoteUpdateModel
    {
        public Guid Id { get; set; }
        public string Description { get; set; }
        public List<string> Tags { get; set; }
        public Guid Category { get; set; }

        public NoteUpdateModel()
        {
            Tags = new List<string>();
        }
    }

    #region Manager Notes

    public class ManagerNoteViewModel
    {
        public string Id { get; set; }
        public int Year { get; set; }
        public string Keyword { get; set; }
        public IEnumerable<string> Tags { get; set; }
        public IEnumerable<NoteViewModel> Notes { get; set; }

        public ManagerNoteViewModel()
        {
            Year = DateTime.Today.Year;
            Tags = Enumerable.Empty<string>();
            Notes = Enumerable.Empty<NoteViewModel>();
        }
    }

    public class ManagerNoteSearchModel
    {
        public string Id { get; set; }
        public int Year { get; set; }
        public string Keyword { get; set; }
        public List<string> Tags { get; set; }

        public ManagerNoteSearchModel()
        {
            Year = DateTime.Today.Year;
            Tags = new List<string>();
        }
    }

    #endregion

    #region My Notes

    public class MyNoteViewModel
    {
        public string Id { get; set; }
        public int Year { get; set; }
        public string Keyword { get; set; }
        public IEnumerable<string> Tags { get; set; }
        public IEnumerable<NoteViewModel> Notes { get; set; }

        public MyNoteViewModel()
        {
            Year = DateTime.Today.Year;
            Tags = Enumerable.Empty<string>();
            Notes = Enumerable.Empty<NoteViewModel>();
        }
    }

    public class MyNoteSearchModel
    {
        public string Id { get; set; }
        public int Year { get; set; }
        public string Keyword { get; set; }
        public List<string> Tags { get; set; }

        public MyNoteSearchModel()
        {
            Year = DateTime.Today.Year;
            Tags = new List<string>();
        }
    }

    #endregion
}